<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_daibao/model')->方法名();
*/
namespace jy_daibao;
defined('BY_JYA') or exit('error');
class merch extends \plugin{
	public function checkmerch(){
		$merchid=pdo_getcolumn('jy_daibao_merch',array('id'=>$_SESSION['merchid'],'uniacid'=>$_SESSION['uniacid']),'id');
		if(!$_SESSION['uid'] || !$merchid || !$_SESSION['merchid']){
			if($_SESSION['uid']){
				$merchid=pdo_getcolumn('jy_daibao_merch',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');
				$member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
				if(!$merchid){
					$insert=array(
						'uniacid'=>$_SESSION['uniacid'],
						'mid'=>$_SESSION['uid'],
						'title'=>$member['title'],
						'mobile'=>$member['mobile'],
						'createtime'=>TIMESTAMP,
					);
					pdo_insert('jy_daibao_merch',$insert);
					$merchid=pdo_insertid();
					$_SESSION['merchid']=$merchid;
				}
			}
			if(!$merchid){
				exi('请先登录！','error','jy_daibao/login/');
			}
		}
		return $merchid;
	}
	public function member_show($id,$default_url='',$default=false){		
		$member=pdo_get('jy_daibao_merch',array('id'=>intval($id)),array('id','name','logo','mobile'));
		if(!$member){
			$member=$default?:array('nickname'=>'无');
		}else{
			$member['nickname']=$member['usename']?:'无';
			$member['avatar']=tomedia($member['avatar']);
		}
		$member['url']='jy_daibao/merch/look/';
		return $member;
	}
}
?>